package com.liusu.spider.js;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;

public class File_{


    public static byte[] readFileToByteArray(File f){
        try {
            byte[] bytes = FileUtils.readFileToByteArray(f);
            return bytes;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static byte[] readFileToByteArray(String path){

        return readFileToByteArray(new File(path));
    }

    public static void writeByteArrayToFile(String path,byte[] bytes){
        try {
            FileUtils.writeByteArrayToFile(new File(path),bytes);

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static List<String> readLines(String path, String charset){
        try {
            return FileUtils.readLines(new File(path),charset);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static List<String> readLines(String path){
        try {
            return FileUtils.readLines(new File(path),"utf-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
